/*
	This file is part of PropExtractor.

	PropExtractor is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	PropExtractor is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with PropExtractor. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _PEINCLUDES_H_
#define _PEINCLUDES_H_

#define _CRT_SECURE_NO_WARNINGS

// Defines

#define PE_VERSION_MAJOR            0
#define PE_VERSION_MINOR            3
#define PE_VERSION_DEBUG            0

#define PE_VERSION_STRING           "0.3.0"

// Includes

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <ShlObj.h>
#include <windows.h>

// GLM
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtc/matrix_transform.hpp>

// DX9
//#include "d3dx9math.h"

#if (defined(PE_STANDALONE) || defined(PE_DLL))

// Debug memory leaks
#	include "crtdbg.h"
#	ifdef _DEBUG
#		ifndef DEBUG_NEW
#			define DEBUG_NEW   new( _NORMAL_BLOCK, __FILE__, __LINE__)
#		endif
#		define new DEBUG_NEW
#	endif

// FreeImage
#	include "FreeImagePlus.h"

// TinyXML
#	include "tinyxml.h"

// ZLib
#	if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
#		include <fcntl.h>
#		include <io.h>
#		define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
#	else
#		define SET_BINARY_MODE(file)
#	endif
#	define CHUNK 16384
#	include "zlib.h"

#endif

#ifdef PE_DLL
#	define PE_DLL_C                 extern "C"
#	define PE_DLL_EXPORT            __declspec(dllexport)
#else
#	ifdef PE_STANDALONE
#		define PE_DLL_C                 
#		define PE_DLL_EXPORT            
#	else
#		define PE_DLL_C                 extern "C"
#		define PE_DLL_EXPORT            __declspec(dllimport)
#	endif
#endif
#define PE_EXPORT                   PE_DLL_C PE_DLL_EXPORT

#define PE_INIT_FUNC(lib, f)        { *(void**)&pe::f = (void*)GetProcAddress(lib, #f); }

#define PE_STRCLRCPY(dst, src) \
{ \
	dst = new char[strlen(src) + 1]; \
	memset(dst, 0, strlen(src) + 1); \
	strcpy(dst, src); \
}

#define PE_WSTRCLRCPY(dst, src) \
{ \
	dst = new wchar_t[wcslen(src) + 1]; \
	memset(dst, 0, (wcslen(src) + 1) * 2); \
	wcscpy(dst, src); \
}

#define PE_WIDETOSTR(dst, src) \
{ \
	unsigned int len = wcslen(src); \
	dst = new char[len + 1]; \
	memset(dst, 0, len + 1); \
	wcstombs(dst, src, len); \
}

#define PE_STRTOWIDE(dst, src) \
{ \
	unsigned int len = strlen(src); \
	dst = new wchar_t[len + 1]; \
	memset(dst, 0, (len + 1) * 2); \
	for (unsigned int index_path = 0; index_path < len; index_path++) \
	{ \
		dst[index_path] = src[index_path]; \
	} \
}

#include "PELog.h"

#ifdef _DEBUG
#	define PE_DEBUG(msg, ...)       PELogWrite(("DEBUG: "msg"\n"), ##__VA_ARGS__)
#else
#	define PE_DEBUG(msg, ...)
#endif
#define PE_ERROR(msg, ...)          PELogWrite(("ERROR! "msg"\n"), ##__VA_ARGS__)
#define PE_STUB()                   PELogWrite(("STUB: %s\n"), __FUNCTION__)
#define PE_PRINT(msg, ...)          PELogWrite((msg"\n"), ##__VA_ARGS__)

// Error codes

#define PE_OK 0

namespace pe
{

	enum ObjectType
	{
		eObjectType_Unknown,
		eObjectType_FileSystem,
		eObjectType_Image,
		eObjectType_Model
	};

	typedef unsigned char		byte;
	typedef unsigned short		word;
	typedef unsigned long		dword;

	struct PEImageRaw;
	struct PEModelRaw;
	struct PEMaterialRaw;
	struct PEMeshRaw;
	struct PEBoneRaw;
	struct PESkinRaw;
	struct PESkinWeightRaw;
	struct PEVertexBuffer;
	struct PENormalBufer;
	struct PETexCoordBuffer;
	struct PEIndexBuffer;

}; // namespace pe
	
#endif